package com.wcarmon.life.command{

    import com.adobe.cairngorm.commands.ICommand
    import com.adobe.cairngorm.control.CairngormEvent;
	import mx.controls.Alert;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.IResponder;
	import com.wcarmon.life.model.LifeModelLocator;
	import com.wcarmon.life.event.GetBlockForProcessingEvent
	import com.wcarmon.life.business.GetBlockDelegate;
	import com.wcarmon.life.vo.BlockVO;
	import mx.utils.ObjectUtil;


	
	public class GetBlockForProcessingCommand implements ICommand, IResponder {
		include "../../includes/loggerSnippet.as";
				
		public function execute( event : CairngormEvent ) : void { 
			var e : GetBlockForProcessingEvent = GetBlockForProcessingEvent( event );
			var model : LifeModelLocator = LifeModelLocator.getInstance();
			
			model.blockToProcessHasLoaded = false;
			( new GetBlockDelegate(this) ).getBlock( e.block_id );
		}
	
	 	public function result( event : Object ) : void {
			var e : ResultEvent = ResultEvent(event);
			var model : LifeModelLocator = LifeModelLocator.getInstance();
			
			if( null == e.result[0] ){
				log.fatal('Got a null block for processing');
				log.fatal( 'e.result = ' + e.result );
				return;
			}
			model.currentProcessBlock = BlockVO.makeBlockFromObject( e.result[0] );			 
			model.blockToProcessHasLoaded = true;
		}
	
		public function fault( event : Object ) : void {
			include "includes/FaultSnippet.as";
		}
	}
}